package com.ruoyi.web.controller.document;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.DocFileManage;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.vo.FileVo;
import com.ruoyi.system.service.DocFileService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 通用请求处理
 *
 * @author ruoyi
 */
@Api(tags = "项目文档管理")
@RestController
@RequestMapping("/doc/pro/file")
public class DocFileController extends BaseController {


    @Autowired
    private DocFileService proService;


    /***
     * 获取项目文档列表信息
     * @param file
     * @return
     */
    @ApiOperation(value = "获取项目文档列表信息")
    @PreAuthorize("@ss.hasPermi('document:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(DocFileManage file) {
        startPage();
        List<FileVo> list = proService.selectProList(file);
        return getDataTable(list);
    }



    /***
     * 新增项目文档信息
     * @param file
     * @return
     */
    @ApiOperation(value = "新增项目文档信息")
    @Log(title = "新增项目文档信息", businessType = BusinessType.INSERT)
    @PreAuthorize("@ss.hasPermi('document:message:save')")
    @PostMapping("/save")
    public AjaxResult add(@Validated @RequestBody DocFileManage file) {
        file.setCreateBy(getUsername());
        return toAjax(proService.insertPro(file));
    }

    /***
     * 修改项目文档信息
     * @param file
     * @return
     */
    @ApiOperation(value = "修改项目文档信息")
    @Log(title = "修改项目文档信息", businessType = BusinessType.UPDATE)
    @PreAuthorize("@ss.hasPermi('document:message:recompose')")
    @PutMapping("update")
    public AjaxResult update(@RequestBody DocFileManage file) {
        file.setUpdateBy(getUsername());
        return toAjax(proService.updateConfig(file));
    }

    /***
     * 逻辑删除项目文档信息
     * @param id
     * @return
     */
    @ApiOperation(value = "逻辑删除项目文档信息")
    @Log(title = "逻辑删除项目文档信息", businessType = BusinessType.DELETE)
    @PreAuthorize("@ss.hasPermi('document:message:romove')")
    @DeleteMapping("/doc/{id}")
    public AjaxResult delete(@PathVariable("id") Long[] id) {
        return toAjax(proService.deleteById(id));
    }

}




